package Dao;

import java.io.IOException;
import java.io.InputStream;


import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import mapper.Coursemapper;
import mapper.Rankmapper;



public class rankdao implements Rankmapper{
	private static Rankmapper rankmapper;
	private static SqlSession session;

	public rankdao() throws IOException {
	 	String resource ="mybatis-config.xml";
		InputStream inputstream = Resources.getResourceAsStream(resource);
		SqlSessionFactory sqlsessionfactory = new SqlSessionFactoryBuilder().build(inputstream);
		session = sqlsessionfactory.openSession();
        rankmapper = session.getMapper(Rankmapper.class);
    }
	public void close(){
		this.session.close();
	}
	@Override
	public boolean UpdateNum(String type) {
		
		boolean iuser = this.rankmapper.UpdateNum(type);
		System.out.println(iuser);
		if(iuser == true){
			session.commit();
		}else{
			session.rollback();
		}
		System.out.println(1111111);
		return iuser;
	}

	@Override
	public int getNum(String type) {
		
		int num = this.rankmapper.getNum(type);
		
		return num;
	}

}
